//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "LigandEpitopeData.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
LigandEpitopeData::LigandEpitopeData (): ligandNumber1(0),
                                         ligandNumber2(0),
                                         secondaryStructureMT(0.0),
                                         compactnessMT(0.0),
                                         lingoSimValue(0.0) {
  
  this->ligandName1 = new String ();
  this->ligandName2 = new String ();
  this->domain1     = new String ();
  this->domain2     = new String ();
  this->toString    = new String ();
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
LigandEpitopeData::LigandEpitopeData (const LigandEpitopeData& ligandEpitopeData): ligandNumber1(ligandEpitopeData.ligandNumber1),
                                                                                   ligandNumber2(ligandEpitopeData.ligandNumber2),
                                                                                   secondaryStructureMT(ligandEpitopeData.secondaryStructureMT),
                                                                                   compactnessMT(ligandEpitopeData.compactnessMT),
                                                                                   lingoSimValue(ligandEpitopeData.lingoSimValue) {
  
  this->ligandName1 = new String (ligandEpitopeData.ligandName1);
  this->ligandName2 = new String (ligandEpitopeData.ligandName2);
  this->domain1     = new String (ligandEpitopeData.domain1);
  this->domain2     = new String (ligandEpitopeData.domain2);
  this->toString    = new String ();
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
LigandEpitopeData::LigandEpitopeData (const LigandEpitopeData* ligandEpitopeData): ligandNumber1(ligandEpitopeData->ligandNumber1),
                                                                                   ligandNumber2(ligandEpitopeData->ligandNumber2),
                                                                                   secondaryStructureMT(ligandEpitopeData->secondaryStructureMT),
                                                                                   compactnessMT(ligandEpitopeData->compactnessMT),
                                                                                   lingoSimValue(ligandEpitopeData->lingoSimValue) {
  
  this->ligandName1 = new String (ligandEpitopeData->ligandName1);
  this->ligandName2 = new String (ligandEpitopeData->ligandName2);
  this->domain1     = new String (ligandEpitopeData->domain1);
  this->domain2     = new String (ligandEpitopeData->domain2);
  this->toString    = new String ();
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
LigandEpitopeData::~LigandEpitopeData () {
  
  if (this->ligandName1) delete this->ligandName1;
  if (this->ligandName2) delete this->ligandName2;
  if (this->domain1)     delete this->domain1;
  if (this->domain2)     delete this->domain2;
  if (this->toString)    delete this->toString;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::LigandName1 (String* ligandName1) {
  
  if (ligandName1) this->ligandName1->In(ligandName1);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::LigandName2 (String* ligandName2) {
  
  if (ligandName2) this->ligandName2->In(ligandName2);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::LigandNumber1 (int ligandNumber1) {
  
  if (ligandNumber1 >= 0) this->ligandNumber1 = ligandNumber1;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::LigandNumber2 (int ligandNumber2) {
  
  if (ligandNumber2 >= 0) this->ligandNumber2 = ligandNumber2;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::Domain1 (String* domain1) {
  
  if (domain1) this->domain1->In(domain1);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::Domain2 (String* domain2) {
  
  if (domain2) this->domain2->In(domain2);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::SecondaryStructureMT (double secondaryStructureMT) {
  
  this->secondaryStructureMT = secondaryStructureMT;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::CompactnessMT (double compactnessMT) {
  
  this->compactnessMT = compactnessMT;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void LigandEpitopeData::LingoSimValue (double lingoSimValue) {
  
  if (lingoSimValue >= 0) this->lingoSimValue = lingoSimValue;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* LigandEpitopeData::LigandName1 (void) {
  
  return this->ligandName1;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* LigandEpitopeData::LigandName2 (void) {
  
  return this->ligandName2;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int LigandEpitopeData::LigandNumber1 (void) {
  
  return this->ligandNumber1;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int LigandEpitopeData::LigandNumber2 (void) {
  
  return this->ligandNumber2;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* LigandEpitopeData::Domain1 (void) {
  
  return this->domain1;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* LigandEpitopeData::Domain2 (void) {
  
  return this->domain2;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
double LigandEpitopeData::SecondaryStructureMT (void) {
  
  return this->secondaryStructureMT;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
double LigandEpitopeData::CompactnessMT (void) {
  
  return this->compactnessMT;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
double LigandEpitopeData::LingoSimValue (void) {
  
  return this->lingoSimValue;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool LigandEpitopeData::LoadData (String* data) {
  
  if (!data || !data->Length()) return false;
  
  return this->LoadData(data->Out());
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool LigandEpitopeData::LoadDataWithoutLingoSim (char* data) {
  
  if (!data || !strlen(data)) return false;
  
  char  ligand1 [40];
  char  ligand2 [40];
  char  domainN1 [80];
  char  domainN2 [80];
  char* part = NULL;
  
  //AP2-1448 FUC-403 >2vqdA02 >1iucA00 -8.37512600861 -20.4269541775
  sscanf (data, "%s %s %s %s %lf %lf %*s",  ligand1, 
                                            ligand2, 
                                            domainN1,
                                            domainN2,
                                            &(this->secondaryStructureMT),
                                            &(this->compactnessMT));
  
  part = strtok (ligand1, "-");
  if (part) this->ligandName1->In(part);
  part = strtok (NULL, "-");
  if (part) this->ligandNumber1 = atoi(part);
    
  part = strtok (ligand2, "-");
  if (part) this->ligandName2->In(part);
  part = strtok (NULL, "-");
  if (part) this->ligandNumber2 = atoi(part);
    
  if (domainN1) this->domain1->In(domainN1 + 1);
  if (domainN2) this->domain2->In(domainN2 + 1);
  
  this->lingoSimValue = 0;
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool LigandEpitopeData::LoadDataWithoutLingoSim (String* data) {
  
  if (!data || !data->Length()) return false;
  
  return this->LoadDataWithoutLingoSim(data->Out());
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool LigandEpitopeData::LoadData (char* data) {
  
  if (!data || !strlen(data)) return false;
  
  char ligandN1 [4];
  char ligandN2 [4];
  char domainN1 [8];
  char domainN2 [8];
  char rest     [200]; 
  
  sscanf (data, "%s-%d %s-%d >%s >%s %lf %lf %lf%s", ligandN1, 
                                                     &(this->ligandNumber1), 
                                                     ligandN2, 
                                                     &(this->ligandNumber2), 
                                                     domainN1,
                                                     domainN2,
                                                     &(this->secondaryStructureMT),
                                                     &(this->compactnessMT),
                                                     &(this->lingoSimValue),
                                                     rest);
  
  if (ligandN1) this->ligandName1->In(ligandN1);
  if (ligandN2) this->ligandName2->In(ligandN2);
  if (domainN1) this->domain1->In(domainN1);
  if (domainN2) this->domain2->In(domainN2);
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* LigandEpitopeData::ToString (void) {
  
  this->toString->In("");
  
  char data [500]; 
  
  sprintf (data, "%s-%d %s-%d >%s >%s %lf %lf %lf\0", this->ligandName1->Out(), 
                                                      this->ligandNumber1, 
                                                      this->ligandName2->Out(), 
                                                      this->ligandNumber2, 
                                                      this->domain1->Out(),
                                                      this->domain2->Out(),
                                                      this->secondaryStructureMT,
                                                      this->compactnessMT,
                                                      this->lingoSimValue);
  
  this->toString->Add(data);
  
  return this->toString;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
LigandEpitopeData LigandEpitopeData::operator= (const LigandEpitopeData& ligandEpitopeData) {
  
  this->ligandName1->In(ligandEpitopeData.ligandName1);
  this->ligandName2->In(ligandEpitopeData.ligandName2);
  this->domain1->In(ligandEpitopeData.domain1);
  this->domain2->In(ligandEpitopeData.domain2);
  
  this->ligandNumber1        = ligandEpitopeData.ligandNumber1;
  this->ligandNumber2        = ligandEpitopeData.ligandNumber2;
  this->secondaryStructureMT = ligandEpitopeData.secondaryStructureMT;
  this->compactnessMT        = ligandEpitopeData.compactnessMT;
  this->lingoSimValue        = ligandEpitopeData.lingoSimValue;
  
  return *this;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
